package cn.edu.cqvie.jdk8.joda;

import java.time.*;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.Set;
import java.util.TreeSet;

public class Java8TimeTest {

    public static void main(String[] args) {
        LocalDate localDate = LocalDate.now();
        System.out.println(localDate);
        System.out.println(localDate.getYear() + ", " + localDate.getMonthValue() + ", " + localDate.getDayOfMonth());

        System.out.println("--------");

        LocalDate localDate1 = LocalDate.of(2019, 1, 5);
        System.out.println(localDate1);

        System.out.println("--------");

        LocalDate localDate2 = LocalDate.of(2019, 3, 25);
        MonthDay monthDay = MonthDay.of(localDate2.getMonth(), localDate2.getDayOfMonth());
        MonthDay monthDay1 = MonthDay.from(LocalDate.of(2019, 3, 25));

        if (monthDay.equals(monthDay1)) {
            System.out.println("equals");
        } else {
            System.out.println("not equals");
        }

        LocalTime localTime = LocalTime.now();
        System.out.println(localTime);

        LocalTime localTime1 = localTime.plusHours(3).plusMinutes(20);
        System.out.println(localTime1);


        LocalDate localDate3 = localDate
                .plus(2, ChronoUnit.WEEKS);
        System.out.println(localDate3);

        System.out.println("-------");

        LocalDate localDate4 = localDate.minus(2, ChronoUnit.MONTHS);
        System.out.println(localDate4);

        System.out.println("-------");
        Clock clock = Clock.systemDefaultZone();
        System.out.println(clock.millis());

        System.out.println("-------");
        LocalDate localDate5 = LocalDate.now();
        LocalDate localDate6 = LocalDate.of(2019, 1, 1);

        //时间比较
        System.out.println(localDate5.isAfter(localDate6));
        System.out.println(localDate5.isBefore(localDate6));
        System.out.println(localDate5.isEqual(localDate6));

        //时区
        Set<String> set = ZoneId.getAvailableZoneIds();
        Set<String> treeSet = new TreeSet<String>() {
            {
                addAll(set);
            }
        };
        treeSet.forEach(System.out::println);
//        set.forEach(System.out::println);


        ZoneId zoneId = ZoneId.of("Asia/Shanghai");
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDateTime);

        ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, zoneId);
        System.out.println(zonedDateTime);


        System.out.println("--------");

        YearMonth yearMonth = YearMonth.now();
        System.out.println(yearMonth);
        System.out.println(yearMonth.lengthOfMonth());
        System.out.println(yearMonth.isLeapYear());

        System.out.println("--------");
        YearMonth yearMonth1 = YearMonth.of(2019, 2);
        System.out.println(yearMonth1);
        System.out.println(yearMonth1.lengthOfMonth());
        System.out.println(yearMonth1.lengthOfYear());
        System.out.println(yearMonth1.isLeapYear());


        System.out.println("--------");
        LocalDate localDate7 = LocalDate.now();
        LocalDate localDate8 = LocalDate.of(2020 , 2, 9);

        //周期性的
        Period period = Period.between(localDate7, localDate8);
        System.out.println(period.getYears());
        System.out.println(period.getMonths());
        System.out.println(period.getDays());

        System.out.println("--------");
        //不带时区的UTC的时间
        System.out.println(Instant.now());
    }
}
